from collections import namedtuple,deque
from enum import Enum
import random

class Operation(Enum):
    login = 1
    pass_ = 2
    fllow_ = 3
    quit_ = 4
    open_ = 5
    close_ = 6
    add_1 = 100
    add_2 = 300
    add_3 = 500

Card = namedtuple("Card",["rank","suit"])
class Deck():
    """
    牌组的基类
    """
    def __init__(self):
        self.ranks = [str(n) for n in range(2, 11)] + list("JQKA")
        self.suits='spades diamonds clubs hearts'.split()
        self.cards = []
    def __getitem__(self, position):
        return self.cards[position]
    def __len__(self):
        return len(self.cards)

class Poker(Deck):
    """"
    这是对整副牌的抽象
    """
    def __init__(self):
        super().__init__()
        self.cards = [Card(r,s) for r in self.ranks for s in self.suits]        
        self.shuffle()
    def pop(self):
        return self.cards.pop()
    def shuffle(self):
        random.shuffle(self.cards)

class MyDeck(Deck):
    """
    玩家牌组的抽象
    """
    def ExtendDeck(self,deck):
        """
        deck: (Card,Card,Card)
        """
        if not len(self.cards):
            self.cards.extend(list(deck))
        else:
            raise Exception("MyDeck.ExtendDeck方法错误,牌组非空,非法操作")
    def getsock(Pokes):
        """
        :param Pokes:是一个deque对象，其中每个元素是Card对象
        :return:
        """
        sock = 0
        # if Pokes[2].num == 1:
        #     sock += 0.14
        # elif Pokes[2].num == 2:
        #     sock += 0.02
        # elif Pokes[2].num == 3:
        #     sock += 0.03
        # elif Pokes[2].num == 4:
        #     sock += 0.04
        # elif Pokes[2].num == 5:
        #     sock += 0.05
        # elif Pokes[2].num == 6:
        #     sock += 0.06
        # elif Pokes[2].num == 7:
        #     sock += 0.07
        # elif Pokes[2].num == 8:
        #     sock += 0.08
        # elif Pokes[2].num == 9:
        #     sock += 0.09
        # elif Pokes[2].num == 10:
        #     sock += 0.1
        # elif Pokes[2].num == 11:
        #     sock += 0.11
        # elif Pokes[2].num == 12:
        #     sock += 0.12
        # else:
        #     sock += 0.13

        if Pokes[0].num == Pokes[1].num and Pokes[0].num == Pokes[2].num:
            sock += 5
            return ('豹子', sock)

        elif Pokes[0].num == Pokes[1].num and Pokes[0].num == Pokes[2].num and \
                Pokes[0].num == (Pokes[1].num) - 1 and Pokes[0].num == (
                Pokes[2].num) - 2:
            sock += 4
            return ('同花顺', sock)

        elif Pokes[0].num == Pokes[1].num and Pokes[0].num == Pokes[2].num % 100:
            sock += 3
            return ('同花', sock)

        elif Pokes[0].num == Pokes[1].num - 1 and Pokes[0].num == Pokes[2].num - 2:
            sock += 2
            return ('顺子', sock)

        elif Pokes[0].num == Pokes[1].num or Pokes[0].num == Pokes[2].num or \
                Pokes[1].num == Pokes[2].num // 100:
            sock += 1
            return ('对子', sock)

        elif Pokes[0].num == 2 and Pokes[1].num == 3 and Pokes[2].num == 5:
            sock -= 1
            return ('豹子杀手', sock)
        else:

            return ('散牌', sock)

    def calculate(Pokes):
        """
        :param Pokes:是一个deque对象，其中每个元素是Card对象
        :return:
        """
        pass

class MyCard(Card):
    def __init__(self,rank,suit):
        self.rank = rank
        self.suit = suit
        self.num = self.GetNum()
        self.path = self.GetPath()

    def GetPath(self):
        if self.suit == "diamonds":
            return f"f{self.num}"
        elif self.suit == "clubs":
            return f"m{self.num}"
        elif self.suit == "hearts":
            return f"t{self.num}"
        elif self.suit == "spades":
            return f"s{self.num}"
        else:
            raise Exception("Path Error",self.suit,self.rank)
if __name__ == "__main__":
    cards = Poker()

